package node.dao;

import hibernate.mappings.HibernateSessionFactory;
import hibernate.mappings.MsNode;
import hibernate.mappings.MySessionFactory;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.jmx.HibernateService;

import util.DBConnection;

public class DocDao {

	public List getDocList(int first,int max) {
		HibernateSessionFactory hsf = new HibernateSessionFactory();
		Session s = hsf.currentSession();
		Query q = s.createQuery("from MsDoc");
		q.setFirstResult(first);
		q.setMaxResults(max);
		List list = q.list();
		return list;
	}

	public List getNodeList(int parent) {
		List list = new ArrayList();
		String sql = "select * from ms_node where parent=" + parent;
		DBConnection dbc = new DBConnection();
		ResultSet rs = dbc.query(sql);
		try {
			while (rs.next()) {
				MsNode node = new MsNode();
				// node.setDocid(rs.getInt("docid"));
				node.setDpub(rs.getInt("dpub"));
				node.setHref(rs.getString("href"));
				node.setId(rs.getInt("id"));
				node.setNpub(rs.getInt("npub"));
				node.setNtype(rs.getInt("ntype"));
				node.setParent(parent);
				// node.setSiteid(rs.getInt("siteid"));
				node.setTablename(rs.getString("tablename"));
				node.setTitle(rs.getString("title"));
				list.add(node);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			dbc.close();
		}

		return list;
	}

}
